<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="回访名称" prop="followName"
                :rules="[
                  { trigger:'blur',required: true,message: '回访名称不能为空'}
                 ]">
              <el-input v-model="inputForm.followName" placeholder="请填写回访名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="病人姓名" prop="patientId"
                :rules="[
                  { trigger:'blur',required: true,message: '病人姓名不能为空'}
                 ]">
                <patient-select :limit='1' :value="inputForm.patientId" @getValue='(value) => {inputForm.patientId=value}'></patient-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="医生姓名" prop="doctorId"
                :rules="[
                  { trigger:'blur',required: true,message: '医生姓名不能为空'}
                 ]">
                <doctor-select :limit='1' :value="inputForm.doctorId" @getValue='(value) => {inputForm.doctorId=value}'></doctor-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="回访时间" prop="followUpDate"
                :rules="[
                  { trigger:'blur',required: true,message: '回访时间不能为空'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.followUpDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="健康状态" prop="healthStatus"
                :rules="[
                  { trigger:'blur',required: true,message: '健康状态不能为空'}
                 ]">
          <el-input type="textarea" v-model="inputForm.healthStatus" placeholder="请填写健康状态"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="内容记录" prop="content"
                        :rules="[
                  { trigger:'blur',required: true,message: '内容记录不能为空'}
                 ]">
            <el-input type="textarea" v-model="inputForm.content" placeholder="请填写内容记录"     ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="下一步治疗建议" prop="nextStep"
                        :rules="[
                  { trigger:'blur',required: true,message: '下一步治疗建议不能为空'}
                 ]">
            <el-input type="textarea" v-model="inputForm.nextStep" placeholder="请填写下一步治疗建议"     ></el-input>
          </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import doctorSelect from '@/components/doctorSelect'
  import patientSelect from '@/components/patientSelect'
  import followUpInfoService from '@/api/follow/followUpInfoService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          followName: '',
          patientId: '',
          doctorId: '',
          followUpDate: '',
          healthStatus: '',
          nextStep: '',
          content: ''
        }
      }
    },
    components: {
      doctorSelect,
      patientSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建回访信息`
        } else if (method === 'edit') {
          this.title = '修改回访信息'
        } else if (method === 'view') {
          this.title = '查看回访信息'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            followUpInfoService.queryById(this.inputForm.id).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            followUpInfoService.save(this.inputForm).then(({data}) => {
              this.visible = false
              this.$message.success(data)
              this.$emit('refreshDataList')
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>


